package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.result.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.ApprovalFormVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-01-04
 */
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Resource
    BorrowerService borrowerService;

    @ApiOperation("借款人审批")
    @PostMapping("approval")
    public R approval(@RequestBody ApprovalFormVO approvalFormVO){
        borrowerService.approval(approvalFormVO);
        return R.ok();
    }

    @ApiOperation("查询借款人详情")
    @GetMapping("{id}")
    public R getById(@PathVariable("id")String id){
        BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetailById(id);
        return R.ok().data("item",borrowerDetailVO);
    }

    @ApiOperation("带条件分页查询借款人列表")
    @GetMapping("/list/{pageNum}/{pageSize}")
    public R listPage(@PathVariable("pageNum")Integer pageNum ,
                      @PathVariable("pageSize")Integer pageSize ,
                      String keyword){
        Page<Borrower> page = borrowerService.listPage(pageNum , pageSize , keyword);
        return R.ok().data("page",page);
    }

}

